package com.fusion.core.settings;

import com.stendahls.util.TextUtils;

import java.lang.reflect.Method;

/**
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 15, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class SettingClass {
    public Object getValue(String k) throws Exception {
        Class<?> c = getClass();
        Method m = c.getMethod("get"+ TextUtils.upperCaseFirstLetter(k));
        return m.invoke(this);
    }

    public void setValue(String name, Object val) throws Exception {
        Class<?> c = getClass();
        Method m;
        try {
            m = c.getMethod("set"+ TextUtils.upperCaseFirstLetter(name), val.getClass());
        } catch(NoSuchMethodException e) {
            val = Integer.parseInt(val.toString());
            m = c.getMethod("set"+ TextUtils.upperCaseFirstLetter(name), val.getClass());
        }
        m.invoke(this, val);
    }
}
